using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
using ControleRepresentanteSync.Application.SimpleSync;
using ControleRepresentanteSync.View.Wizard;

namespace ControleRepresentanteSync.View.SimpleSync
{
    internal abstract class SimpleSyncSelectionViewModel<TContentViewModel, TModel, TItem, TContract> : WizardPageViewModelBase, ISimpleSyncSelectionViewModel<TContentViewModel, TModel, TItem, TContract> 
        where TContentViewModel : ISimpleSyncContentViewModel<TModel, TItem, TContract>
        where TItem : ISimpleSycItem<TContract>
    {
        public static readonly DependencyProperty IsAllCheckedProperty = 
            DependencyProperty.Register("IsAllChecked", typeof(bool), typeof(SimpleSyncSelectionViewModel<TContentViewModel, TModel, TItem, TContract>), new PropertyMetadata(OnIsAllCheckedChanged));

        private static void OnIsAllCheckedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((SimpleSyncSelectionViewModel<TContentViewModel, TModel, TItem, TContract>) d).FireIsAllCheckedChanged();
        }

        private void FireIsAllCheckedChanged()
        {
            if (IsAllCheckedChanged != null)
                IsAllCheckedChanged(this, EventArgs.Empty);
        }

        public bool IsAllChecked
        {
            get { return (bool) GetValue(IsAllCheckedProperty); }
            set { SetValue(IsAllCheckedProperty, value); }
        }

        public event EventHandler IsAllCheckedChanged;

        private readonly ObservableCollection<TContentViewModel> m_ToSync;

        protected SimpleSyncSelectionViewModel(string title, string description)
            : base(title, description)
        {
            m_ToSync = new ObservableCollection<TContentViewModel>();
        }

        public IList<TContentViewModel> ToSync { get { return m_ToSync; } }
    }
}